<extend name="Base/common"/>
<block name="head_css">
    <style>

        .z_photo {
            width: 98%;
            min-height: 5rem;
            overflow: hidden;
            zoom: 1;
            padding: 0.3rem;
            clear: both;
            margin: 1rem auto;
        }

        .z_photo img {
            width: 100%;
        }

        .z_addImg {
            float: left;
            margin-right: 0.5rem;
            width: 3rem;
            height: 3rem;
        }

        .z_file {
            width: 3rem;
            height: 3rem;
            background: url(__IMG__/z_add.png) no-repeat;
            background-size: 100% 100%;
            float: left;
            margin-right: 0.2rem;
        }

        .z_file input::-webkit-file-upload-button {
            width: 1rem;
            height: 1rem;
            border: none;
            position: absolute;
            outline: 0;
            opacity: 0;
        }

        .z_file input#file {
            display: block;
            width: 3rem;
            border: 0;
            vertical-align: middle;
            height: 3rem;
            opacity: 0;
        }
        /*遮罩层*/

        .z_mask {
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, .5);
            position: fixed;
            top: 0;
            left: 0;
            z-index: 999;
            display: none;
        }

        .z_alert {
            width: 10rem;
            height: 3rem;
            border-radius: .2rem;
            background: #fff;
            font-size: .24rem;
            text-align: center;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -5rem;
            margin-top: -2rem;
        }

        .z_alert p:nth-child(1) {
            line-height: 1.5rem;
        }

        .z_alert p:nth-child(2) span {
            display: inline-block;
            width: 49%;
            height: 1.5rem;
            line-height: 1.5rem;
            float: left;
            border-top: 1px solid #ddd;
        }

        .z_cancel {
            border-right: 1px solid #ddd;
        }

    </style>
</block>
<block name="body">

    <form id="form-post" action="{:U('upload')}" method="post" accept-charset="utf-8" enctype="multipart/form-data" onsubmit="return check_form()" >
        <input type="hidden" name="cate_id" value="{$cate_id}"/>
        <div class="aui-content aui-margin-b-15">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-header">填写信息</li>
                <div class="z_photo">
                    <div class="z_file">
                        <input type="file" name="file[]" id="file" value="" accept="image/*" multiple onchange="imgChange('z_photo','z_file',this);" />
                    </div>
                </div>
                <!--遮罩层-->

                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">
                            姓名
                        </div>
                        <div class="aui-list-item-input">
                            <input type="text" name="name" placeholder="姓名">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">
                            电话
                        </div>
                        <div class="aui-list-item-input">
                            <input type="number" name="tel" placeholder="电话">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">
                            内容
                        </div>
                        <div class="aui-list-item-input">
                            <textarea name="content" placeholder="留下您想说的"></textarea>
                        </div>
                    </div>
                </li>
                <div style="height: 0.5rem;"></div>
                <input class="sub" type="submit" name="提交">
                <div style="height: 0.5rem;"></div>
            </ul>
        </div>
    </form>

    <div style="width: 100%;height: 3.5rem;background: #eceef3;"></div>

</block>
<block name="footer_js">
    <script>
        function  check_form(){
            var name = $("#form-post input[name='name']").val()
            var tel = $("#form-post input[name='tel']").val()
            var content = $("#form-post textarea[name='content']").val()
            var patrn=/^[\u4e00-\u9fa5\uf900-\ufa2d]{1,4}$/;
            if(!patrn.exec(name)){
                alert("请输入你的名字，1-4个汉字");
                return false;
            }
            patrn=/^1[34578]\d{9}$/;
            if(!patrn.exec(tel)){
                alert("请输入正确的电话号码");
                return false;
            }
            if($.trim(content)==""){
                alert('内容不能为空！');
                return false;
            }


        }
    </script>
    <script type="text/javascript">
        //px转换为rem


        function imgChange(obj1, obj2,v) {
            //获取点击的文本框
            var file = document.getElementById("file");
            //存放图片的父级元素
            var imgContainer = document.getElementsByClassName(obj1)[0];
            //获取的图片文件
            var fileList = file.files;
            //文本框的父级元素
            var input = document.getElementsByClassName(obj2)[0];
            var imgArr = [];
            //遍历获取到得图片文件
            for (var i = 0; i < fileList.length; i++) {
                var imgUrl = window.URL.createObjectURL(file.files[i]);
                imgArr.push(imgUrl);
                var img = document.createElement("img");
                img.setAttribute("src", imgArr[i]);
                var imgAdd = document.createElement("div");
                imgAdd.setAttribute("class", "z_addImg");
                imgAdd.appendChild(img);
                imgContainer.appendChild(imgAdd);
            };
            imgRemove();
            $(v).attr("id","");
            $(".z_file").hide();

            var str='<div class="z_file">'+
                '<input type="file" name="file[]" id="file" value="" accept="image/*" multiple onchange="imgChange(\'z_photo\',\'z_file\',this);" />'+
                '</div>';
            $(".z_photo").append(str);

        };

        function imgRemove() {
            var imgList = document.getElementsByClassName("z_addImg");
            var mask = document.getElementsByClassName("z_mask")[0];
            var cancel = document.getElementsByClassName("z_cancel")[0];
            var sure = document.getElementsByClassName("z_sure")[0];
            for (var j = 0; j < imgList.length; j++) {
                imgList[j].index = j;
                imgList[j].onclick = function() {
                    var t = this;
                    mask.style.display = "block";
                    cancel.onclick = function() {
                        mask.style.display = "none";
                    };
                    sure.onclick = function() {
                        mask.style.display = "none";
                        t.style.display = "none";
                    };

                }
            };
        };

    </script>
</block>